package com.zmn.oms.api.listener;

import com.alibaba.fastjson.JSON;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.manager.utils.OmsMqTagConsts;
import com.zmn.oms.model.entity.warn.OrderWarnReplyEvent;
import com.zmn.oms.zmn.business.interfaces.open.OrderWarnReplyNotifyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 类描述：订单预警回复推送
 *
 * @author LiangHailong
 * @date 2019/07/30 15:16
 */
@AliyunMQListener(topic = "${spring.mq.topic.oms}")
@Component
public class OrderWarnReplyListener {

    private static final Logger logger = LoggerFactory.getLogger(OrderWarnReplyListener.class);

    /**
     * 新单
     *
     * @param message
     */
    @AliyunMQHandler(tags = OmsMqTagConsts.ZMN_TOPIC_OMS_ORDER_WARN_REPLY_SYNC_API)
    public void orderNew(String message) {
        try {
            logger.info("#mq#order#sync#orderWarn#recive message:{}", message);
            OrderWarnReplyEvent orderWarnReplyEvent = JSON.parseObject(message, OrderWarnReplyEvent.class);
            OrderWarnReplyNotifyService orderWarnReplyNotifyService = OrderChangeNotifyFactory.getOrderWarnReplyNotifyInstance(orderWarnReplyEvent);
            if (orderWarnReplyNotifyService != null) {
                orderWarnReplyNotifyService.notifyOrderWarnReply(orderWarnReplyEvent);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}
